<template>
  <el-card class="box-card" style="margin-bottom:10px">
    <el-form :inline="true" :model="formInline" class="demo-form-inline" :disabled="isDisable">
      <el-form-item label="一级分类">
        <el-select v-model="category1Id" placeholder="请选择">
          <el-option :label="c1.name" v-for="c1 in categoryStore.category1List" :key="c1.id" :value="c1.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="category2Id" placeholder="请选择">
          <el-option :label="c2.name" v-for="c2 in categoryStore.category2List" :key="c2.id" :value="c2.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="category3Id" placeholder="请选择">
          <el-option :label="c3.name" v-for="c3 in categoryStore.category3List" :key="c3.id" :value="c3.id" />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang="ts">
export default {
  name: "CategorySelector",
};
</script>

<script lang="ts" setup>
import { reactive,onMounted,computed } from 'vue'
import { reqGetCategory1ListData } from '@/api/product/category'

import { useCategoryListStore } from '@/stores/categoryList'

// 接收 三级导航禁用
const props = defineProps(['isDisable'])
const categoryStore = useCategoryListStore()
const formInline = reactive({
  user: '',
  region:''
})

// 一挂载就渲染页面
onMounted(() => {
  // const res = await  reqGetCategory1ListData() 
  // console.log('c1',res);
  categoryStore.getCategory1ListData()
  
})

const onSubmit = ()=>{
  console.log('submit');
  
}

// 使用计算属性来精简一级分类id
const category1Id = computed<number>({
  get(){
     return categoryStore.category1Id as number
  },
  set(val){
    //获取二级数据
     categoryStore.getCategory2ListData(val)
  }
})
//使用计算属性精简二级分类id 
const category2Id = computed<number>({
  get(){
     return categoryStore.category2Id as number
  },
  set(val){
    categoryStore.getCategory3ListData(val) 
  }
})
//使用计算属性精简三级分类id 
const category3Id = computed<number>({
  get(){
     return categoryStore.category3Id as number
  },
  set(val){
    categoryStore.setCategory3Id(val)
  }
})
</script>

<style scoped></style>